home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / error.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  121 lines

  1. /* Test classes Catch, ExceptionAction, and ExceptionTrap
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    error.c,v $
  26.  * Revision 3.0  90/05/20  00:29:02  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/error.c,v 3.0 90/05/20 00:29:02 kgorlen Rel $";
  31.  
  32. #include "Stack.h"
  33. #include "Exception.h"
  34. #include "nihclIO.h"
  35. #include "nihclerrs.h"
  36.  
  37. void xtrap(unsigned& err, int& sev, ...)
  38. {
  39.     cerr << "xtrap(" << err << ',' << sev << ") called\n";
  40. }
  41.  
  42. class MyClass : public VIRTUAL Object {
  43.     DECLARE_MEMBERS(MyClass);
  44.     int n;
  45.     Catch catcherr;
  46. public:
  47.     MyClass(int i) : catcherr(this) {
  48.         n = i;
  49.         cerr << "MyClass(" << n << ") constructed\n";
  50.     }
  51.     virtual void deepenShallowCopy();
  52.     virtual void destroyer() {
  53.         cerr << "MyClass(" << n << ") destroyed\n";
  54.     }
  55.     virtual unsigned hash() const;
  56.     virtual bool isEqual(const Object&) const;
  57.     virtual void printOn(ostream& strm =cout) const;
  58. private:            // shouldNotImplement()
  59.     virtual int compare(const Object&) const;
  60. };
  61.  
  62. #define    THIS    MyClass
  63. #define    BASE    Object
  64. #define    BASE_CLASSES BASE::desc()
  65. #define    MEMBER_CLASSES
  66. #define    VIRTUAL_BASE_CLASSES
  67.  
  68. DEFINE_CLASS(MyClass,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/error.c,v 3.0 90/05/20 00:29:02 kgorlen Rel $",NULL,NULL);
  69.  
  70. MyClass::MyClass(OIOifd& fd) : Object(fd) { fd >> n; }
  71.  
  72. MyClass::MyClass(OIOin& strm) : Object(strm) { strm >> n; }
  73.  
  74. void MyClass::deepenShallowCopy() {};
  75.  
  76. unsigned MyClass::hash() const    { return (unsigned)this; }
  77.  
  78. bool MyClass::isEqual(const Object& a) const { return isSame(a); }
  79.  
  80. void MyClass::printOn(ostream& strm) const {}
  81.  
  82. int MyClass::compare(const Object&) const
  83. {
  84.     shouldNotImplement("compare");
  85.     return 0;
  86. }
  87.  
  88. main()
  89. {
  90.     cerr << "Test classes Catch, ExceptionAction, and ExceptionTrap\n";
  91.     Stack s;
  92.     MyClass* p = new MyClass(-1);
  93.     MyClass* q = new MyClass(-2);
  94.     {
  95.         MyClass a(1);
  96.         MyClass b(2);
  97.         RaiseException x(NIHCL__CLTNEMPTY);
  98.         BEGINX
  99.             MyClass c(3);
  100.             MyClass d(4);
  101.             {
  102.                 MyClass e(5);
  103.                 MyClass f(6);
  104.                 delete p;
  105.                 s.pop();
  106.             }
  107.         EXCEPTION
  108.             case NIHCL__CLTNEMPTY: {
  109.                 MyClass g(7);
  110.                 MyClass h(8);
  111.                 cerr << "CLTNEMPTY error handled\n";
  112.             }
  113.         ENDX
  114.     }
  115.     delete q;
  116.     {
  117.         ExceptionTrap x(xtrap);
  118.         s.pop();
  119.     }
  120. }
  121.